package cn.glccc.system.controller;

import cn.glccc.common.vo.Result;
import cn.glccc.ds.base.controller.BaseController;
import cn.glccc.system.entity.SysUser;
import cn.glccc.system.service.ISysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户表 控制器
 *
 * @author glccc
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends BaseController<ISysUserService, SysUser> {

    /**
     * 校验用户名是否存在
     *
     * @param username
     * @return
     */
    @GetMapping("/validate/username")
    public Result<?> validateUsername(String username) {
        LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SysUser::getUsername, username);
        long count = this.baseService.count(lqw);
        return Result.success(count > 0);
    }

    /**
     * 校验手机号是否存在
     *
     * @param phone
     * @return
     */
    @GetMapping("/validate/phone")
    public Result<?> validatePhone(String phone) {
        LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SysUser::getPhone, phone);
        long count = this.baseService.count(lqw);
        return Result.success(count > 0);
    }

}
